<?php
/**
 * @author Mingming Tang iamalazyrat@gmail.com
 */

class Sign_Controller extends Base_Controller {

  public $restful = true;

  public function get_index() {
    return Redirect::to(url('sign/in'));
  }

  public function get_in() {
    return View::make('sign.in.main');
  }

  public function post_auth() {
      $input = Input::all();
      if (!isset($input['password']) OR !isset($input['email'])) return Response::json(array('code'=>400, 'msg'=>'登录邮箱或密码为空')); 

      $credentials = array('username' => $input['email'], 'password' => $input['password']);

      if (Auth::attempt($credentials)){ 
        return Response::json(array('code'=>200, 'msg'=>'登录成功'));
      } else {
        return Response::json(array('code'=>400, 'msg'=>'用户名或密码不正确'));
      }
    
  }

  public function get_out() {
    Auth::logout();
    return Redirect::to('/');
  }
  
}
